import axios from "axios";

const request = axios.create({
    baseURL: "http://localhost:8080",
    timeout: 5000
})

//  Axios 请求拦截器——获取LocalStorage中的Token并增加请求头
request.interceptors.request.use(
    (config) => {
        const userInfo = JSON.parse(localStorage.getItem("user"))

        if (userInfo && userInfo.token) {
            config.headers.Authorization = "Bearer " + userInfo.token;
        }
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
)

export default request;
